package o;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;

public final class fxr {
    static final Logger ˊ = Logger.getLogger(fxr.class.getName());

    class AnonymousClass2 extends fxd {
        final /* synthetic */ Socket ˋ;

        AnonymousClass2(Socket socket) {
            this.ˋ = socket;
        }

        protected IOException ˋ(@Nullable IOException iOException) {
            IOException socketTimeoutException = new SocketTimeoutException("timeout");
            if (iOException != null) {
                socketTimeoutException.initCause(iOException);
            }
            return socketTimeoutException;
        }

        protected void ॱ() {
            try {
                this.ˋ.close();
            } catch (Throwable e) {
                fxr.ˊ.log(Level.WARNING, "Failed to close timed out socket " + this.ˋ, e);
            } catch (AssertionError e2) {
                if (fxr.ˋ(e2)) {
                    fxr.ˊ.log(Level.WARNING, "Failed to close timed out socket " + this.ˋ, e2);
                    return;
                }
                throw e2;
            }
        }
    }

    class AnonymousClass3 implements fxx {
        final /* synthetic */ fxv ˊ;
        final /* synthetic */ OutputStream ˋ;

        AnonymousClass3(fxv o_fxv, OutputStream outputStream) {
            this.ˊ = o_fxv;
            this.ˋ = outputStream;
        }

        public void ˎ(fxi o_fxi, long j) throws IOException {
            fxy.ˊ(o_fxi.ˎ, 0, j);
            while (j > 0) {
                this.ˊ.ʼ();
                fxt o_fxt = o_fxi.ॱ;
                int min = (int) Math.min(j, (long) (o_fxt.ˋ - o_fxt.ˎ));
                this.ˋ.write(o_fxt.ˏ, o_fxt.ˎ, min);
                o_fxt.ˎ += min;
                j -= (long) min;
                o_fxi.ˎ -= (long) min;
                if (o_fxt.ˎ == o_fxt.ˋ) {
                    o_fxi.ॱ = o_fxt.ˎ();
                    fxs.ˊ(o_fxt);
                }
            }
        }

        public void flush() throws IOException {
            this.ˋ.flush();
        }

        public void close() throws IOException {
            this.ˋ.close();
        }

        public fxv ˊ() {
            return this.ˊ;
        }

        public String toString() {
            return "sink(" + this.ˋ + ")";
        }
    }

    class AnonymousClass4 implements fxw {
        final /* synthetic */ InputStream ˎ;
        final /* synthetic */ fxv ˏ;

        AnonymousClass4(fxv o_fxv, InputStream inputStream) {
            this.ˏ = o_fxv;
            this.ˎ = inputStream;
        }

        public long ˊ(fxi o_fxi, long j) throws IOException {
            if (j < 0) {
                throw new IllegalArgumentException("byteCount < 0: " + j);
            } else if (j == 0) {
                return 0;
            } else {
                try {
                    this.ˏ.ʼ();
                    fxt ˏ = o_fxi.ˏ(1);
                    int read = this.ˎ.read(ˏ.ˏ, ˏ.ˋ, (int) Math.min(j, (long) (8192 - ˏ.ˋ)));
                    if (read == -1) {
                        return -1;
                    }
                    ˏ.ˋ += read;
                    o_fxi.ˎ += (long) read;
                    return (long) read;
                } catch (AssertionError e) {
                    if (fxr.ˋ(e)) {
                        throw new IOException(e);
                    }
                    throw e;
                }
            }
        }

        public void close() throws IOException {
            this.ˎ.close();
        }

        public fxv ˊ() {
            return this.ˏ;
        }

        public String toString() {
            return "source(" + this.ˎ + ")";
        }
    }

    private fxr() {
    }

    public static fxg ˎ(fxw o_fxw) {
        return new fxp(o_fxw);
    }

    public static fxj ˋ(fxx o_fxx) {
        return new fxq(o_fxx);
    }

    public static fxx ॱ(OutputStream outputStream) {
        return ˎ(outputStream, new fxv());
    }

    private static fxx ˎ(OutputStream outputStream, fxv o_fxv) {
        if (outputStream == null) {
            throw new IllegalArgumentException("out == null");
        } else if (o_fxv != null) {
            return new AnonymousClass3(o_fxv, outputStream);
        } else {
            throw new IllegalArgumentException("timeout == null");
        }
    }

    public static fxx ॱ(Socket socket) throws IOException {
        if (socket == null) {
            throw new IllegalArgumentException("socket == null");
        } else if (socket.getOutputStream() == null) {
            throw new IOException("socket's output stream == null");
        } else {
            fxv ˏ = ˏ(socket);
            return ˏ.ˎ(ˎ(socket.getOutputStream(), ˏ));
        }
    }

    public static fxw ˋ(InputStream inputStream) {
        return ˏ(inputStream, new fxv());
    }

    private static fxw ˏ(InputStream inputStream, fxv o_fxv) {
        if (inputStream == null) {
            throw new IllegalArgumentException("in == null");
        } else if (o_fxv != null) {
            return new AnonymousClass4(o_fxv, inputStream);
        } else {
            throw new IllegalArgumentException("timeout == null");
        }
    }

    public static fxw ॱ(File file) throws FileNotFoundException {
        if (file != null) {
            return ˋ(new FileInputStream(file));
        }
        throw new IllegalArgumentException("file == null");
    }

    public static fxx ˏ(File file) throws FileNotFoundException {
        if (file != null) {
            return ॱ(new FileOutputStream(file));
        }
        throw new IllegalArgumentException("file == null");
    }

    public static fxx ˋ(File file) throws FileNotFoundException {
        if (file != null) {
            return ॱ(new FileOutputStream(file, true));
        }
        throw new IllegalArgumentException("file == null");
    }

    public static fxx ˎ() {
        return new fxx() {
            public void ˎ(fxi o_fxi, long j) throws IOException {
                o_fxi.ʼ(j);
            }

            public void flush() throws IOException {
            }

            public fxv ˊ() {
                return fxv.ॱ;
            }

            public void close() throws IOException {
            }
        };
    }

    public static fxw ˎ(Socket socket) throws IOException {
        if (socket == null) {
            throw new IllegalArgumentException("socket == null");
        } else if (socket.getInputStream() == null) {
            throw new IOException("socket's input stream == null");
        } else {
            fxv ˏ = ˏ(socket);
            return ˏ.ˎ(ˏ(socket.getInputStream(), ˏ));
        }
    }

    private static fxd ˏ(Socket socket) {
        return new AnonymousClass2(socket);
    }

    static boolean ˋ(AssertionError assertionError) {
        return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true;
    }
}
